home *** CD-ROM | disk | FTP | other *** search
Wrap
Attribute VB_Name = "Primary" Option Explicit Public MyWorkspace As Workspace Public sTestPath As String Public dbTest As Database Public sDataPath As String Public bFound As Boolean Public bFirst As Boolean Public oError As New ErrorHandler '---------------------------------------------------------------------' Sub Main() bFirst = True sDataPath = CurDir & "\" sTestPath = sDataPath & "Test.mdb" Call OpenDatabases frmNames.Show End Sub '---------------------------------------------------------------------' Public Sub OpenDatabases() Dim iCount As Integer Set MyWorkspace = DBEngine.Workspaces(0) For iCount = 0 To 20 Set dbTest = MyWorkspace.OpenDatabase(sTestPath, _ False, False, ";PWD=") Select Case Err.Number Case 0: Exit For Case 3050: If iCount = 20 Then MsgBox "The Test database is locked by another user. If you cannot get into the program after a few tries, then check to see if another user is editing the Access database or if a user is locked in this program.", vbCritical + vbOKOnly, "Database is locked" CloseAll EndApp Exit Sub End If End Select Next End Sub '---------------------------------------------------------------------' Public Sub DBCompact() '-- Unload anything that accesses the database(s) Unload frmNames '-- Call CloseAll On Error GoTo AAARRRGGGHHH '-- Delete old backup files If Not Dir(sDataPath & "OldTest.mdb") = vbNullString Then Call Kill(sDataPath & "OldTest.mdb") '-- Rename current files to backup file names (keeps other users from accessing through pgm) Name sDataPath & "Test.mdb" As sDataPath & "OldTest.mdb" '-- Repair the backup files Call DBEngine.RepairDatabase(sDataPath & "OldTest.mdb") '-- Compact the backup files back into the datafiles Call DBEngine.CompactDatabase(sDataPath & "OldTest.mdb", sDataPath & "Test.mdb") GoTo SkipAAARRRGGGHHH AAARRRGGGHHH: If Not oError(Err.Number, "Error compacting databases") Then Resume SkipAAARRRGGGHHH: On Error GoTo 0 bFirst = True Call OpenDatabases '-- Show the forms again frmNames.Show End Sub '---------------------------------------------------------------------' Public Sub CloseAll() dbTest.Close MyWorkspace.Close Set MyWorkspace = Nothing Set dbTest = Nothing End Sub '---------------------------------------------------------------------' Public Sub EndApp() End End Sub